/*
 * Copyright (C), 2002-2017, 苏宁易购电子商务有限公司
 * FileName: ActivityController.java
 * Author:   15060460
 * Date:     2017年4月6日 下午2:55:26
 * Description: //模块目的、功能描述      
 * History: //修改记录
 * <author>      <time>      <version>    <desc>
 * 修改人姓名             修改时间            版本号                  描述
 */
package com.suning.sawp.in.controller.member;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.suning.framework.lang2.exception.BizzException;
import com.suning.sawp.constants.ClerkConstants;
import com.suning.sawp.constants.LoggerConstants;
import com.suning.sawp.dto.common.EmployeeInfo;
import com.suning.sawp.dto.common.ReturnMsg;
import com.suning.sawp.dto.storeman.Category;
import com.suning.sawp.in.filter.RequestUserHolder;
import com.suning.sawp.intf.maindiscode.MainDiscodeService;
import com.suning.sawp.intf.store.StoreInfoService;
import com.suning.sawp.member.constant.MemberConstants;
import com.suning.sawp.member.dto.AdminActivity;
import com.suning.sawp.member.service.ActivityService;
import com.suning.sawp.member.service.AdminActivityService;
import com.suning.sawp.member.vo.ActivityStoreListVo;
import com.suning.sawp.member.vo.ActivityStoreVo;
import com.suning.sawp.member.vo.AdminActivityVo;
import com.suning.sawp.member.vo.CustomerDetailVo;
import com.suning.sawp.member.vo.CustomerDetailWithSaleVo;
import com.suning.sawp.member.vo.GridViewVo;
import com.suning.sawp.service.util.DateUtils;

/**
 * 后台活动相关controller
 *
 * @author 15060460
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Controller
@RequestMapping("/adminPage/activity")
public class ActivityController {

	private static final Logger LOGGER = LoggerFactory.getLogger(LoggerConstants.SAWP_SERVICE);

	@Autowired
	private AdminActivityService adminActivityService;

	@Autowired
	private ActivityService activityService;

	@Autowired
	private StoreInfoService storeInfoService;

	@Resource
	MainDiscodeService mainDiscodeService;

	/**
	 * 后台活动查询(大区、分公司)
	 *
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	@RequestMapping("queryActivityList")
	@ResponseBody
	public ReturnMsg<GridViewVo<AdminActivity>> queryActivityVo(@RequestParam(defaultValue = "1") Long pageNo, @RequestParam(defaultValue = "10") Long pageSize) {
		ReturnMsg<GridViewVo<AdminActivity>> returnMsg = new ReturnMsg<GridViewVo<AdminActivity>>();
		EmployeeInfo employee = RequestUserHolder.getRequestUser();
		GridViewVo<AdminActivity> viewVo = null;
		try {
			if (employee.getOrgLevel().equals(MemberConstants.EmployeeOrgLevel.HQ)) {// 总部查看所有活动
				viewVo = adminActivityService.queryActivityList(null, null, pageNo, pageSize);
			} else if (employee.getOrgLevel().equals(MemberConstants.EmployeeOrgLevel.AREA)) {// 大区
				viewVo = adminActivityService.queryActivityList(employee.getRegion5Code(), "0", pageNo, pageSize);
			} else if (StringUtils.equals(employee.getOrgLevel(), MemberConstants.EmployeeOrgLevel.CAMPANY)) {// 分公司
				viewVo = adminActivityService.queryActivityList(employee.getBranchCode(), "1", pageNo, pageSize);
			} else {
				throw new BizzException(employee.getOrgLevel() + ",权限不足");
			}
		} catch (Exception e) {
			LOGGER.error("queryActivityVo异常", e);
			returnMsg.setRetFlag(ReturnMsg.FAIL);
			returnMsg.setErrorMessage(e.getMessage());
		}
		returnMsg.setData(viewVo);
		return returnMsg;
	}

	/**
	 * 报表后台活动下拉列表查询(总部、大区、分公司、店长、督导)
	 *
	 * @return
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	@RequestMapping("queryActivityForSelect")
	@ResponseBody
	public ReturnMsg<List<AdminActivity>> queryActivityForSelect(String areaCode) {
		ReturnMsg<List<AdminActivity>> returnMsg = new ReturnMsg<List<AdminActivity>>();
		EmployeeInfo employee = RequestUserHolder.getRequestUser();
		List<AdminActivity> activities = null;
		try {
			if (employee.getOrgLevel().equals("0")) {// 总部先选大区，在查询活动
				if (StringUtils.isNotEmpty(areaCode)) {
					activities = adminActivityService.queryActivityList(getReginCode5(areaCode), "0", null, null).getData();// 下拉列表没分页
				} else {
					throw new BizzException("areaCode不能为空");
				}
			} else if (employee.getOrgLevel().equals("2")) {// 大区
				activities = adminActivityService.queryActivityList(employee.getRegion5Code(), "0", null, null).getData();
			} else if (StringUtils.equals(employee.getOrgLevel(), "1")) {// 分公司1
				activities = adminActivityService.queryActivityList(employee.getBranchCode(), "1", null, null).getData();
			} else if (StringUtils.equals(employee.getOrgLevel(), "4") && (StringUtils.equals(employee.getPositionId(), ClerkConstants.STORE_KEEPER))) {// 店长
				activities = adminActivityService.queryActivityList(employee.getStoreCode(), null);
			} else if (StringUtils.equals(employee.getOrgLevel(), "4") && StringUtils.equals(employee.getPositionId(), ClerkConstants.SALE_GUIDE)) {// 督导
				activities = adminActivityService.queryActivityList(employee.getStoreCode(), employee.getStaffId());
			} else {
				throw new BizzException(employee.getOrgLevel() + ",权限不足");
			}
		} catch (Exception e) {
			LOGGER.error("queryActivityVo异常", e);
			returnMsg.setRetFlag(ReturnMsg.FAIL);
			returnMsg.setErrorMessage(e.getMessage());
		}
		returnMsg.setData(activities);
		return returnMsg;
	}

	/**
	 * 后台活动删除(大区、分公司)
	 *
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	@SuppressWarnings("rawtypes")
	@RequestMapping("deleteActivity")
	@ResponseBody
	public ReturnMsg deleteActivity(Long activityId) {
		ReturnMsg returnMsg = new ReturnMsg();
		try {
			if (activityId == null) {
				throw new BizzException("activityId不能为空");
			}
			EmployeeInfo employee = RequestUserHolder.getRequestUser();
			returnMsg = activityService.deleteActivity(activityId, employee.getStaffId(), false);
		} catch (Exception e) {
			LOGGER.error("deleteActivity异常", e);
			returnMsg.setRetFlag(ReturnMsg.FAIL);
			returnMsg.setErrorMessage(e.getMessage());
		}
		return returnMsg;
	}

	/**
	 * 
	 * 查询门店列表(大区、分公司)
	 *
	 * @return
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	@RequestMapping("queryStoreList")
	@ResponseBody
	public ReturnMsg<ActivityStoreListVo> queryStoreList(@RequestParam(required = false, defaultValue = "N") String storeType) {
		ReturnMsg<ActivityStoreListVo> returnMsg = new ReturnMsg<ActivityStoreListVo>();
		try {
			EmployeeInfo employee = RequestUserHolder.getRequestUser();
			String storeTypeCode = getStoreType(storeType);
			ActivityStoreListVo listVo = this.adminActivityService.queryStoreList(employee, storeTypeCode);
			returnMsg.setData(listVo);
		} catch (Exception e) {
			LOGGER.error("queryStoreList异常", e);
			returnMsg.setRetFlag(ReturnMsg.FAIL);
			returnMsg.setErrorMessage(e.getMessage());
		}
		return returnMsg;
	}

	private String getStoreType(String storeType) {
		String transformType = MemberConstants.SHOP_TYPE_MAP.get(storeType);
		// 不是 M,S,N，则默认返回 N 的数据
		if (StringUtils.isEmpty(transformType)) {
			transformType = MemberConstants.SHOP_TYPE_MAP.get(MemberConstants.NORMAL_SHOP);
		}
		return transformType;
	}

	/**
	 * 
	 * 查询活动信息(大区、分公司)
	 *
	 * @return
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	@RequestMapping("findActivityDetail4Mod")
	@ResponseBody
	public ReturnMsg<AdminActivityVo> queryOneActivity(String activityId) {
		ReturnMsg<AdminActivityVo> returnMsg = new ReturnMsg<AdminActivityVo>();
		try {
			if (StringUtils.isEmpty(activityId)) {
				throw new BizzException("activityId不能为空");
			}
			returnMsg.setData(adminActivityService.queryActivity(activityId));
		} catch (Exception e) {
			LOGGER.error("findActivityDetail4Mod异常", e);
			returnMsg.setRetFlag(ReturnMsg.FAIL);
			returnMsg.setErrorMessage(e.getMessage());
		}
		return returnMsg;
	}

	/**
	 * 
	 * 修改活动信息(大区、分公司)
	 *
	 * @return
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	@SuppressWarnings("rawtypes")
	@RequestMapping(value = "modifyActivity", method = RequestMethod.POST)
	@ResponseBody
	public ReturnMsg modifyActivity(@RequestBody AdminActivityVo adminActivityVo) {
		ReturnMsg returnMsg = new ReturnMsg();
		try {
			if (adminActivityVo == null || StringUtils.isEmpty(adminActivityVo.getId())) {
				throw new BizzException("活动编码不能为空");
			}
			checkAdminActivityVo(adminActivityVo);
			adminActivityService.modifyActivity(adminActivityVo, RequestUserHolder.getRequestUser().getStaffId());
		} catch (Exception e) {
			LOGGER.info("入参：{}", adminActivityVo);
			LOGGER.error("modifyActivity异常", e);
			returnMsg.setRetFlag(ReturnMsg.FAIL);
			returnMsg.setErrorMessage(e.getMessage());
		}
		return returnMsg;
	}

	private void checkAdminActivityVo(AdminActivityVo vo) throws UnsupportedEncodingException {
		if (StringUtils.isEmpty(vo.getName())) {
			throw new BizzException("活动名称不能为空");
		}
		if (vo.getName().length() > 20) {
			throw new BizzException("活动名称超过20个字符");
		}
		if (StringUtils.isEmpty(vo.getStartTime())) {
			throw new BizzException("开始时间不能为空");
		}
		Date d = DateUtils.getDateByStr(vo.getStartTime());
		if (d == null) {
			throw new BizzException("开始时间格式不正确");
		}
		if (StringUtils.isEmpty(vo.getEndTime())) {
			throw new BizzException("结束时间不能为空");
		}
		d = DateUtils.getDateByStr(vo.getEndTime());
		if (d == null) {
			throw new BizzException("结束时间格式不正确");
		}
		if (CollectionUtils.isEmpty(vo.getStores())) {
			throw new BizzException("关联门店不能为空");
		}
		Map<String, String> storeCodes = new HashMap<String, String>();
		for (ActivityStoreVo store : vo.getStores()) {
			if (StringUtils.isEmpty(store.getStoreCode()) || StringUtils.isEmpty(store.getStoreName())) {
				throw new BizzException("关联门店编码或名称不能为空");
			}
			if (!NumberUtils.isNumber(store.getTargetAmount()) || NumberUtils.createBigDecimal(store.getTargetAmount()).compareTo(BigDecimal.ZERO) <= 0) {
				throw new BizzException("目标金额不正确");
			}

			if (storeCodes.containsKey(store.getStoreCode())) {
				throw new BizzException("关联门店重复");
			} else {
				storeCodes.put(store.getStoreCode(), store.getStoreCode());
			}
		}

	}

	/**
	 * 
	 * 修改活动信息(大区、分公司)
	 *
	 * @return
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	@RequestMapping(value = "addActivity", method = RequestMethod.POST)
	@ResponseBody
	public ReturnMsg<String> addActivity(@RequestBody AdminActivityVo adminActivityVo) {
		ReturnMsg<String> returnMsg = new ReturnMsg<String>();
		try {
			checkAdminActivityVo(adminActivityVo);
			String activityId = adminActivityService.addActivity(adminActivityVo, RequestUserHolder.getRequestUser());
			returnMsg.setData(activityId);
		} catch (Exception e) {
			LOGGER.info("入参：{}", adminActivityVo);
			LOGGER.error("addActivity异常", e);
			returnMsg.setRetFlag(ReturnMsg.FAIL);
			returnMsg.setErrorMessage(e.getMessage());
		}
		return returnMsg;
	}

	/**
	 * 8位大区编码转换成5位
	 *
	 * @param reginCode8
	 * @return
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	private String getReginCode5(String reginCode8) {
		// 转换5位大区编码
		return mainDiscodeService.queryRegion5CdBy8Cd(reginCode8);
	}

	/**
	 *
	 * @param createTime
	 *            转移此时间之后的客户
	 * @param secretKey
	 *            如果没传createTime 表示是转移所有的客户，这是个危险的操作，你得知道规则，才可以操作
	 * 
	 */
	@RequestMapping("processOldCust")
	@ResponseBody
	public ReturnMsg<String> processOldCust(String createTime, String secretKey, HttpServletRequest request) {
		ReturnMsg<String> returnMsg = new ReturnMsg<String>();
		String custNo = request.getRemoteUser();
		if (!("12061818".equals(custNo) || "15050536".equals(custNo) || "14080292".equals(custNo))) {
			returnMsg.setRetFlag(ReturnMsg.FAIL);
			returnMsg.setErrorMessage("权限不足");
			return returnMsg;
		}

		if (StringUtils.isEmpty(createTime)) {
			if (checkSec(secretKey)) {
				// 处理全客户
				activityService.processOldCust(StringUtils.EMPTY);
			} else {
				returnMsg.setRetFlag(ReturnMsg.FAIL);
				returnMsg.setErrorMessage("口令不正确，禁止操作");
				return returnMsg;
			}
		} else {
			// 处理时间段后发展的客户
			activityService.processOldCust(createTime);
		}
		returnMsg.setData("数据已处理完成，请通过app或后台验证");
		return returnMsg;
	}

	/**
	 * 计算密钥，判断与传递来的是否一致，如果匹配上，则通过，否则拒绝处理
	 *
	 * @param secretKey
	 */
	private boolean checkSec(String secretKey) {
		Date date = new Date();
		String s = DateUtils.getDateStrByFormat(date, "yyyy-MM-dd-HH");
		String[] data = s.split("-");
		int result = 0;
		for (String item : data) {
			result += Integer.parseInt(item);
		}
		String caculateKey = result + data[data.length - 1];
		if (caculateKey.equals(secretKey)) {
			return true;
		}
		return false;
	}

	/**
	 * 
	 * 根据活动id和店员工号查询发展的客户数据
	 *
	 * @param activityId
	 *            活动id
	 * @param employeeId
	 *            员工工号
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("queryCustomerDetailByEmployeeId")
	@ResponseBody
	public ReturnMsg queryCustomerDetailByEmployeeId(Long activityId, String employeeId, String source, @RequestParam(defaultValue = "1") int pageNo, @RequestParam(defaultValue = "10") int pageSize) {
		ReturnMsg returnMsg = new ReturnMsg();
		if (activityId == null || StringUtils.isEmpty(employeeId)) {
			returnMsg.setRetFlag(ReturnMsg.FAIL);
			returnMsg.setErrorMessage("参数异常");
			return returnMsg;
		}
		GridViewVo<CustomerDetailVo> list = adminActivityService.queryCustomerDetailByEmployeeId(activityId, employeeId, source, pageNo, pageSize);
		returnMsg.setData(list);
		return returnMsg;
	}

	/**
	 * 
	 * 根据活动id和店员工号查询发展的客户数据,附带其消费数据
	 *
	 * @param activityId
	 *            活动id
	 * @param employeeId
	 *            员工工号
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * @throws JsonProcessingException
	 */
	@RequestMapping("queryCustomerDetailWithSaleByEmployeeId")
	@ResponseBody
	public ReturnMsg queryCustomerDetailWithSaleByEmployeeId(Long activityId, String employeeId, String source, @RequestParam(defaultValue = "1") int pageNo,
			@RequestParam(defaultValue = "10") int pageSize) {
		ReturnMsg returnMsg = new ReturnMsg();
		if (activityId == null || StringUtils.isEmpty(employeeId)) {
			setParamErrorInfo(returnMsg);
			return returnMsg;
		}
		GridViewVo<CustomerDetailWithSaleVo> list = adminActivityService.queryCustomerDetailWithSaleByEmployeeId(activityId, employeeId, source, pageNo, pageSize);
		returnMsg.setData(list);
		return returnMsg;
	}

	/**
	 * 查询门店维度的拓展客户数据
	 * 
	 * @return
	 * @RequestMapping("queryCustomerDetailByStore")
	 * @ResponseBody public ReturnMsg queryCustomerDetailByStore(Long
	 *               activityId, String storeCode, String source,
	 * @RequestParam(defaultValue = "1") int pageNo,
	 * @RequestParam(defaultValue = "10") int pageSize) { LOGGER.debug(
	 *                            "queryCustomerDetailByStore的参数为 activityId:{}，storeCode:{}，source:{}"
	 *                            , activityId, storeCode, source); ReturnMsg
	 *                            returnMsg = new ReturnMsg(); EmployeeInfo
	 *                            employee = RequestUserHolder.getRequestUser();
	 *                            if (employee == null || employee.getOrgLevel()
	 *                            == null) { LOGGER.error("employee信息异常：{}",
	 *                            employee); throw new
	 *                            BizzException("登录员工信息异常"); } if (activityId ==
	 *                            null) { setParamErrorInfo(returnMsg);
	 *                            LOGGER.error(
	 *                            "[queryCustomerDetailByStore]的必填参数 activityId为null，登录人为：{}"
	 *                            , employee); return returnMsg; } int orgLevel
	 *                            = Integer.parseInt(employee.getOrgLevel()); //
	 *                            只有总部，大区，分公司，门店的店长，才可以访问此接口;其余的都会返回权限不足异常 if
	 *                            ((orgLevel != 0 && orgLevel != 1 && orgLevel
	 *                            != 2 && orgLevel != 4) ||
	 *                            StringUtils.equals(employee.getPositionId(),
	 *                            ClerkConstants.SALE_GUIDE)) { throw new
	 *                            BizzException(orgLevel + ",权限不足"); } // 店长 if
	 *                            (MemberConstants
	 *                            .EmployeeOrgLevel.SHOP.equals(
	 *                            employee.getOrgLevel()) &&
	 *                            StringUtils.equals(employee.getPositionId(),
	 *                            ClerkConstants.STORE_KEEPER)) { storeCode =
	 *                            employee.getStoreCode(); LOGGER.debug(
	 *                            "[queryCustomerDetailByStore]登录的角色为店长，门店编码取店长自身的门店属性,storeCode:{}"
	 *                            , storeCode); } // 总部，大区，分公司门店编码从前端页面传过来 if
	 *                            (StringUtils.isEmpty(storeCode)) {
	 *                            setParamErrorInfo(returnMsg);
	 *                            LOGGER.error("[queryCustomerDetailByStore]的必填参数 storeCode为空，登录人为：{}"
	 *                            , employee); return returnMsg; } // 查询数据
	 *                            List<CustomerDetailVo> list =
	 *                            adminActivityService.
	 *                            queryCustomerDetailByStoreAndCateCode
	 *                            (activityId, storeCode, null, source, pageNo,
	 *                            pageSize); returnMsg.setData(list); return
	 *                            returnMsg; }
	 */

	/**
	 * 
	 * 合并出的一个方法
	 *
	 * @param type
	 *            0：查普通数据，1：含销售数据
	 * @param activityId
	 * @param storeCode
	 * @param cateCode
	 * @param source
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	private ReturnMsg checkAndQueryByStoreAndCate(int type, Long activityId, String storeCode, String cateCode, String source, int pageNo, int pageSize) {
		LOGGER.debug("checkAndQueryByStoreAndCate的参数为 activityId:{}，storeCode:{}，cateCode:{},source:{},type:{}", activityId, storeCode, cateCode, source, type);
		ReturnMsg returnMsg = new ReturnMsg();
		EmployeeInfo employee = RequestUserHolder.getRequestUser();
		if (employee == null || employee.getOrgLevel() == null) {
			LOGGER.error("employee信息异常：{}", employee);
			throw new BizzException("登录员工信息异常");
		}
		// 如果是督导访问
		if (StringUtils.equals(employee.getPositionId(), ClerkConstants.SALE_GUIDE)) {
			storeCode = employee.getStoreCode();
			cateCode = getCateCode(employee.getCategoryes());
			LOGGER.debug("checkAndQueryByStoreAndCate,当前登录的人员为督导：{}，门店编码为：{}，品类编码为：{}", employee.getName(), storeCode, cateCode);

			// 督导的品类，是查询自身品类，如果为空，则不可以继续获取数据了
			if (StringUtils.isEmpty(cateCode)) {
				setParamErrorInfo(returnMsg);
				LOGGER.error("[checkAndQueryByStoreAndCate]的必填参数 storeCode为空，登录人为：{}", employee);
				return returnMsg;
			}

		} else if (StringUtils.equals(employee.getPositionId(), ClerkConstants.STORE_KEEPER)) { // 店长访问
			storeCode = employee.getStoreCode();
			LOGGER.debug("[checkAndQueryByStoreAndCate]登录的角色为店长，门店编码取店长自身的门店属性,storeCode:{}", storeCode);
		}

		// 总部，大区，分公司门店编码从前端页面传过来
		if (activityId == null || StringUtils.isEmpty(storeCode)) {
			setParamErrorInfo(returnMsg);
			LOGGER.error("[checkAndQueryByStoreAndCate]的必填参数 storeCode为空，登录人为：{}", employee);
			return returnMsg;
		}
		// 查询数据
		if (type == 0) {
			GridViewVo<CustomerDetailVo> list = adminActivityService.queryCustomerDetailByStoreAndCateCode(activityId, storeCode, cateCode, source, pageNo, pageSize);
			returnMsg.setData(list);
		} else {
			GridViewVo<CustomerDetailWithSaleVo> list = adminActivityService.queryCustomerDetailWithSaleByStoreAndCateCode(activityId, storeCode, cateCode, source, pageNo, pageSize);
			returnMsg.setData(list);
		}
		return returnMsg;
	}

	/**
	 * 
	 * 按门店，按品类查询所有发展的客户 （总部，大区，店长，督导 都有可能）
	 *
	 */
	@RequestMapping("queryCustomerDetailByStoreCodeAndCateCode")
	@ResponseBody
	public ReturnMsg queryCustomerDetailByStoreCodeAndCateCode(Long activityId, String storeCode, String cateCode, String source, @RequestParam(defaultValue = "1") int pageNo,
			@RequestParam(defaultValue = "10") int pageSize) {
		return checkAndQueryByStoreAndCate(0, activityId, storeCode, cateCode, source, pageNo, pageSize);
	}

	/**
	 * 
	 * 按门店，按品类查询所有发展的客户 ,含销售信息（总部，大区，店长，督导 都有可能）
	 *
	 */
	@RequestMapping("queryCustomerDetailWithSaleByStoreCodeAndCateCode")
	@ResponseBody
	public ReturnMsg queryCustomerDetailWithSaleByStoreCodeAndCateCode(Long activityId, String storeCode, String cateCode, String source, @RequestParam(defaultValue = "1") int pageNo,
			@RequestParam(defaultValue = "10") int pageSize) {
		return checkAndQueryByStoreAndCate(1, activityId, storeCode, cateCode, source, pageNo, pageSize);
	}

	private String getCateCode(List<Category> categories) {
		if (CollectionUtils.isEmpty(categories)) {
			return StringUtils.EMPTY;
		}
		if (categories.size() == 1) {
			return categories.get(0).getCategoryCode();
		}
		StringBuilder sb = new StringBuilder();
		for (Category c : categories) {
			sb.append(c.getCategoryCode()).append(",");
		}
		return sb.toString().substring(0, sb.toString().length() - 1);
	}

	private void setParamErrorInfo(ReturnMsg<?> returnMsg) {
		returnMsg.setRetFlag(ReturnMsg.FAIL);
		returnMsg.setErrorMessage("参数异常");
	}
}
